﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;



public partial class InventoryTracker_InvoiceDeta : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            txtDateTime.Text = System.DateTime.Now.ToString();
        }
        
        
    }

    protected void ddrInvNo_SelectedIndexChanged(object sender, EventArgs e)
    {
        

        int x = ddrInvNo.SelectedIndex;
        string InvoiceNumber = ddrInvNo.SelectedValue;

        string constr= ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        String sql="SELECT [CustName], [CustAddr1], [CustAddr2], [CustAddr3], [CustCity], [CustState], [CustStatus],[CustFax], [CustMobile], [CustPhone], [CustCountry], [CustEmail], [CustZipCode] FROM [CustomerMaster] WHERE ([CustStatus] > 0) AND [CustID]=(SELECT [CustID] FROM [Invoice] WHERE ([InvoiceNumber] ="+InvoiceNumber+"))";
        SqlCommand cmd = new SqlCommand(sql, con);

        DataTable dataTable = GetDataTable(cmd);
        string val = dataTable.Rows[0]["CustName"].ToString() + "<br>" + dataTable.Rows[0]["CustAddr1"].ToString();

        String sql1 = "SELECT [InvoiceDiscount],[Tax],[InvoiceTotalAmount],[Grandtotal],[Invoicedate] FROM [InvoiceDetails] WHERE ([InvoiceNumber] =" + InvoiceNumber + ")";
        SqlCommand cmd1 = new SqlCommand(sql1, con);

        DataTable dataTable1 = GetDataTable(cmd1);
        DiscLabel.Text = dataTable1.Rows[0]["InvoiceDiscount"].ToString();
        TaxxLabel.Text = dataTable1.Rows[0]["Tax"].ToString();
        GraTotLabel2.Text = dataTable1.Rows[0]["Grandtotal"].ToString();
        txtDateTime.Text = dataTable1.Rows[0]["Invoicedate"].ToString();
              
        

       if (!String.IsNullOrEmpty( dataTable.Rows[0]["CustAddr2"].ToString()) )
       {
            val = val + "<br>" + dataTable.Rows[0]["CustAddr2"].ToString();
       }
      // val = dataTable.Rows[0]["CustName"].ToString() + "<br>" + dataTable.Rows[0]["CustAddr1"].ToString() + "<br>" + dataTable.Rows[0]["CustAddr2"].ToString();
       if (!String.IsNullOrEmpty(dataTable.Rows[0]["CustAddr3"].ToString()))
       {
           val = val + "<br>" + dataTable.Rows[0]["CustAddr3"].ToString();
       }
       val = val + dataTable.Rows[0]["CustCity"].ToString() + "-" + dataTable.Rows[0]["CustZipCode"].ToString() + "<br>" + dataTable.Rows[0]["CustState"].ToString() + "<br>" + dataTable.Rows[0]["CustCountry"].ToString();
       if (!String.IsNullOrEmpty(dataTable.Rows[0]["CustMobile"].ToString()))
       {
           val = val + "<br> <b> Mobile: </b>" + dataTable.Rows[0]["CustMobile"].ToString();
       }
       if (!String.IsNullOrEmpty(dataTable.Rows[0]["CustPhone"].ToString()))
       {
           val = val + "<br> <b> Ph:</b>" + dataTable.Rows[0]["CustPhone"].ToString();
       }
       if (!String.IsNullOrEmpty(dataTable.Rows[0]["CustFax"].ToString()))
       {
           val = val + "<br> <b> Fax:</b>" + dataTable.Rows[0]["CustFax"].ToString();
       }
       
       if (!String.IsNullOrEmpty(dataTable.Rows[0]["CustEmail"].ToString()))
       {
           val = val + "<br> <b>E-Mail:</b>" + dataTable.Rows[0]["CustEmail"].ToString();
       }
       //val = val + "<br>" + dataTable.Rows[0]["CustPhone"].ToString() + "<br>" + dataTable.Rows[0]["CustFax"].ToString() + "<br>" + dataTable.Rows[0]["CustMobile"].ToString() + "<br>" + dataTable.Rows[0]["CustEmail"].ToString();
       int r = dataTable.Rows.Count;
       CustLabel.Text = val;

       
        // string val1 = "Name:" + "<br>" + "Address 1:" + "<br>" + " Address 2:" + "<br>" + "Address 3:" + "<br>" + "City:"+"<br>"+"State:"+"<br>"+"Country:"+"<br>"+"Phone No:"+"<br>"+"Mobile No:"+"<br>"+"Fax:"+"<br>"+"E-Mail Id:"+"<br>"+"ZipCode:";
      // CustInfLabel.Text = val1;
        con.Close(); 
    }
    public static DataTable GetDataTable(SqlCommand cmd)
    {
       
            SqlDataAdapter da = new SqlDataAdapter();
            //set the SelectCommand of the adapter
            da.SelectCommand = cmd;
            // create a new DataTable
            DataTable dtGet = new DataTable();
            //fill the DataTable
            da.Fill(dtGet);
            //return the DataTable
            return dtGet;

        }
    

    
    protected void DiscountTextBox_TextChanged(object sender, EventArgs e)
    {
        //{
        //    String T = String.Empty;
        //    GridViewRow r =  GridView1.FooterRow;
        //    T = (((TextBox)r.FindControl("DiscountTextBox")).Text);
        //    Response.Write("T:"  +T);
        //}
        //int T = 0;

        //GridViewRow Row = GridView1.FooterRow;
        //T = int.Parse(((TextBox)Row.FindControl("DiscountTextBox")).Text);
    }
    
    
    protected void txtPlace_TextChanged(object sender, EventArgs e)
    {
        
        
    }
}
